import type { FieldRule } from 'vant'

// 存放校验规则
const mobileRules = [
  { required: true, message: '请输入手机号' },
  {
    // digital 数字 \d
    pattern: /^1[3-9]\d{9}$/,
    message: '请输入正确的手机号'
  }
]
const passwordRules = [
  { required: true, message: '请输入密码' },
  {
    // word 字符 \w
    pattern: /^\w{8,24}$/,
    message: '请输入8~24个字符'
  }
]

const codeRules: FieldRule[] = [
  {
    required: true,
    message: '请输入验证码'
  },
  {
    // 6位数字验证码
    pattern: /^\d{6}$/,
    message: '请输入6位数字验证码'
  }
]

const nameRules: FieldRule[] = [
  {
    required: true,
    message: '请输入姓名'
  },
  {
    pattern: /^(?:[\u4e00-\u9fa5·]{2,16})$/,
    message: '请输入2-16个中文字符'
  }
]

const idCardRules: FieldRule[] = [
  {
    required: true,
    message: '请输入身份证号'
  },
  {
    pattern:
      /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/,
    message: '身份格式有误'
  }
]

export { mobileRules, passwordRules, codeRules, nameRules, idCardRules }
